package com.xiexiaozhou.helper.web.controller;

import com.xiexiaozhou.helper.core.domain.Customer;
import com.xiexiaozhou.helper.core.domain.Order;
import com.xiexiaozhou.helper.core.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    /**
     * 跳转到顾客个人信息页
     *
     * @return
     */
    @GetMapping("/index")
    public String index() {
        return "/customer/index";
    }

    /**
     * 用户注销
     *
     * @param session
     * @return
     */
    @GetMapping("/logout")
    public String logout(HttpSession session) {
        session.removeAttribute("customer");
        return "/customer/index";
    }

    @GetMapping("/applyToDistributor")
    public String applyToDistributor(@RequestParam Long id, Model model) {
        Customer customer = customerService.applyToDistributor(id);
        if (customer != null) {
            model.addAttribute("message", "申请中");
        }
        return "/customer/index";
    }

}
